#include "xsheetwidget.h"
#include <iostream>
xSheetWidget::xSheetWidget()
{
    set_size_request(200,500);
    mySurface = Gdk::Pixmap::create(mySurface,400,400,24);
    myContext = mySurface->create_cairo_context();
    myContext->set_source_rgb(1,1,1);
    myContext->paint();
    refresh();
};

xSheetWidget::~xSheetWidget()
{
};
void xSheetWidget::load(Glib::RefPtr<smil::BasicTiming> load_ptr) // Aim at a new element
{
    focus = load_ptr;
    refresh();
};

void xSheetWidget::refresh() // recalculate the display
{
    if (!focus)// is it empty?
    {
        set_size_request(50,50);
        Gdk::Cairo::set_source_color(myContext, get_style()->get_bg(Gtk::STATE_INSENSITIVE));// Just print gray.
        myContext->paint();
    }
    else if (focus->get_qname() == "par")// is it a par?
    {   std::cout << "par";// if so, create the columns
        std::cout << focus->children.size() << " children";} // and run each column
    else // Otherwise it's a seq or body
    std::cout << "sequential type"; // so we'll parse it directly as a column.
};

bool xSheetWidget::on_motion_notify_event(GdkEventMotion* event)
{
    return false;
};
bool xSheetWidget::on_key_press_event(GdkEventKey* event)
{
    return false;
};
bool xSheetWidget::on_expose_event(GdkEventExpose* event)
{
    blit(event->area);
    return true; // handled
};

void xSheetWidget::blit(GdkRectangle area)
{
    get_bin_window()->draw_drawable (Gdk::GC::create(get_bin_window()), mySurface, area.x, area.y, area.x, area.y, area.width, area.height);
}
